package cn.hesion.goods.controller;
/**
 * ClassName: BrandController <br/>
 * Description: <br/>
 * date: 2020/12/15 17:35<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import cn.hesion.entity.Result;
import cn.hesion.entity.StatusCode;
import cn.hesion.goods.pojo.Brand;
import cn.hesion.goods.sevices.IBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: changgou-parent
 * @description:
 * @author: hesion
 * @create: 2020-12-15 17:35
 **/
@RestController
@RequestMapping("/brand")
@CrossOrigin
public class BrandController {

    @Autowired
    IBrandService brandService;

    /**
     * @return cn.hesion.entity.Result
     * @Author hst
     * @Description //TODO 修改品牌
     * @Date 12:12 2020/12/16
     * @Param [brand]
     **/
    @PutMapping()
    public Result editBrand(@RequestBody Brand brand) {
        brandService.updateBrandByKey(brand);
        return new Result(true, StatusCode.OK, "编辑成功");
    }

    /**
     * @return cn.hesion.entity.Result
     * @Author hst
     * @Description //TODO 新增品牌
     * @Date 12:11 2020/12/16
     * @Param [brand]
     **/
    @PostMapping()
    public Result AddBrand(@RequestBody Brand brand) {
        brandService.insertBrand(brand);
        return new Result(true, StatusCode.OK, "添加成功");
    }

    /**
     * @return cn.hesion.entity.Result<java.util.List < cn.hesion.goods.pojo.Brand>>
     * @Author hst
     * @Description //TODO 查询所以品牌
     * @Date 11:59 2020/12/16
     * @Param []
     **/
    @GetMapping()
    public Result<List<Brand>> findAllBrand() {
        List<Brand> brands = brandService.getAllBrand();
        return new Result<List<Brand>>(true, StatusCode.OK, "查询成功", brands);
    }

    /**
     * @return cn.hesion.entity.Result<cn.hesion.goods.pojo.Brand>
     * @Author hst
     * @Description //TODO 查询单个品牌
     * @Date 11:59 2020/12/16
     * @Param [id]
     **/
    @GetMapping("/{id}")
    public Result<Brand> findBrandById(@PathVariable("id") Integer id) {
        Brand brand = brandService.findBrandById(id);
        return new Result<Brand>(true, StatusCode.OK, "查询成功", brand);
    }
}
